#!/usr/bin/bash -x

echo Working ...

USER=root
PASSWORD=Password123
DB=freedom
HOST=localhost
CMD_OPT_HELP=0

function print_help {
cat <<_EOF_
Usage: `basename $0` [OPTIONS]
	-u USER		Defined the user.
				Defaults
					$PASSWORD
	-d DB		Defined the database.
				Defaults
					$DB
	-p PASSWORD Defined the password.
				Defaults
					$PASSWORD
	-h HOST		Defined the host.
				Defaults
					$HOST
_EOF_
}

while getopts "h:u:p:d:" OPTION
do
  case $OPTION in
  	h) HOST=$OPTARG ;;
  	u) USER=$OPTARG ;;
  	p) PASSWORD=$OPTARG ;;
  	d) DB=$OPTARG ;;
  	*) CMD_OPT_HELP=1 ;;
  esac
done

if [ "$CMD_OPT_HELP" -eq 1 ] ; then
	print_help
	exit 0
fi

echo host: $HOST
echo user: $USER
echo password: $PASSWORD
echo db: $DB
mysql -h $HOST -s -u $USER --password=$PASSWORD $DB < gen-drop-schema-mysql.sql > drop-schema-mysql.sql
mysql -h $HOST -u $USER --password=$PASSWORD $DB < drop-schema-mysql.sql
mysql -h $HOST -u $USER --password=$PASSWORD $DB < freedom-schema.sql